using System;
using System.Collections;
using System.Collections.Specialized;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.Windows.Forms;
using Syncfusion.XlsIO;

namespace ctsu.Admin.Forms
{
	public partial class frmRoomReports : Form
	{
		enum RoomType
		{
			Exam,
			Consult,
		}

		OrderedDictionary _odRooms;
		OrderedDictionary _odConcurrent;
		OrderedDictionary _odSummaryHours;

		const double _totExamRooms = 4;
		const double _totConsultRooms = 2;
		const double _totRooms = 6;

		int _interval = 1;

		public frmRoomReports()
		{
			InitializeComponent();
		}

		private void InitializeUsage()
		{
			_odRooms = new OrderedDictionary();

			foreach (Control ctl in pnlRooms.Controls)
			{
				if (ctl is CheckBox)
				{
					CheckBox cb = ctl as CheckBox;
					if (cb.Checked)
					{
						Room rm = new Room();
						rm.Name = cb.Text;
						rm.Val = int.Parse(cb.Tag.ToString());
						rm.OdUsage = new OrderedDictionary();
						InitializeRoom(rm);
						_odRooms.Add(rm.Val, rm);
					}
				}
			}
		}

		private void InitializeRoom(Room room)
		{
			DateTime dtStart = StartDate.Value;
			DateTime dtEnd = EndDate.Value;

			if (rdo1.Checked)
				_interval = 1;
			else if (rdo7.Checked)
				_interval = 7;
			else if (rdo14.Checked)
				_interval = 14;
			else if (rdo28.Checked)
				_interval = 28;

			DateTime dtInterval = new DateTime(dtStart.Ticks);

			while (dtInterval.CompareTo(dtEnd) <= 0)
			{
				RoomUsage u = new RoomUsage();
				u.VisitDate = dtInterval;
				u.Duration = 0;
				room.OdUsage.Add(dtInterval, u);
				dtInterval = dtInterval.AddDays(_interval);
			}
		}

		//room usage - for each day, for each room - cumulative total hours used
		private void btnProcess_Click(object sender, EventArgs e)
		{
			if (StartDate.IsNullDate || EndDate.IsNullDate)
			{
				MessageBox.Show("Select start and end dates");
				return;
			}

			InitializeUsage();
			string sql = "TRUNCATE TABLE RoomUsage";
			string connStr = ConfigurationManager.ConnectionStrings["CreamConnectString"].ToString();
			try
			{
				using (SqlConnection conn = new SqlConnection(connStr))
				{
					conn.Open();
					SqlCommand cmd = new SqlCommand(sql, conn);
					cmd.ExecuteNonQuery();


					sql = "SELECT VisitDate, Room1 AS Room, Rm1TimeIn AS TimeIn, " +
						"Rm1TimeOut AS TimeOut FROM ProtocolVisitOutPatient " +
						"WHERE (Room1 IS NOT NULL AND Room1> 1) AND VisitDate BETWEEN '" + StartDate.Value.ToShortDateString() + "' AND '" + EndDate.Value.ToShortDateString() + "' " +
						" UNION " +
						"SELECT VisitDate, Room2 AS Room, Rm2TimeIn AS TimeIn, " +
						"Rm2TimeOut AS TimeOut FROM ProtocolVisitOutPatient " +
						"WHERE (Room2 IS NOT NULL AND Room2 > 1) AND VisitDate BETWEEN '" + StartDate.Value.ToShortDateString() + "' AND '" + EndDate.Value.ToShortDateString() + "' " +
						" ORDER BY VisitDate";

					if (chkAdditional.Checked)
					{
						sql = "SELECT VisitDate, Room1 AS Room, Rm1TimeIn AS TimeIn, " +
							"Rm1TimeOut AS TimeOut FROM ProtocolVisitOutPatient " +
							"WHERE (Room1 IS NOT NULL AND Room1> 1) AND VisitDate BETWEEN '" + StartDate.Value.ToShortDateString() + "' AND '" + EndDate.Value.ToShortDateString() + "' " +
							" UNION " +
							"SELECT VisitDate, Room2 AS Room, Rm2TimeIn AS TimeIn, " +
							"Rm2TimeOut AS TimeOut FROM ProtocolVisitOutPatient " +
							"WHERE (Room2 IS NOT NULL AND Room2 > 1) AND VisitDate BETWEEN '" + StartDate.Value.ToShortDateString() + "' AND '" + EndDate.Value.ToShortDateString() + "' " +
							" UNION " +
							"SELECT VisitDate, Room1 AS Room, Rm1TimeIn AS TimeIn, " +
							"Rm1TimeOut AS TimeOut FROM AdditionalRoomUsage " +
							"WHERE (Room1 IS NOT NULL AND Room1> 1) AND VisitDate BETWEEN '" + StartDate.Value.ToShortDateString() + "' AND '" + EndDate.Value.ToShortDateString() + "' " +
							" UNION " +
							"SELECT VisitDate, Room2 AS Room, Rm2TimeIn AS TimeIn, " +
							"Rm2TimeOut AS TimeOut FROM AdditionalRoomUsage " +
							"WHERE (Room2 IS NOT NULL AND Room2 > 1) AND VisitDate BETWEEN '" + StartDate.Value.ToShortDateString() + "' AND '" + EndDate.Value.ToShortDateString() + "' " +
							" ORDER BY VisitDate";

					}

					cmd = new SqlCommand(sql, conn);
					SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
					while (rdr.Read())
					{
						int iRoom = rdr.GetInt32(1);
						if (!_odRooms.Contains(iRoom))
							continue;

						Room rm = (Room)_odRooms[(object)iRoom];

						DateTime vDate = rdr.GetDateTime(0);
						string tIn = rdr.GetString(2);
						string tOut = rdr.GetString(3);

						decimal hrs = GetHours(tIn, tOut);
						AddRoomHrs(rm, vDate, hrs);
					}
					rdr.Close();
				}
				InsertIntoTable();
				string url = Properties.Settings.Default.Crema2_ReportingServices_ReportingService.ToString().Trim();
				string server = GetServerFromUrl(url);
				StringBuilder sb = new StringBuilder("http://" + server + "/reportserver?");
				sb.Append("/GCRC/Room+Usage&rs:Command=Render");
				System.Diagnostics.Process.Start(sb.ToString());
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
		}

		private void AddRoomHrs(Room room, DateTime dt, decimal hrs)
		{
			DateTime key = GetKey(dt, room.OdUsage.Keys);
			if (room.OdUsage.Contains(key))
			{
				RoomUsage ru = (RoomUsage)room.OdUsage[key];
				ru.Duration += hrs;
			}
		}

		private DateTime GetKey(DateTime dt, ICollection keys)
		{
			DateTime dtRet = new DateTime();
			foreach (DateTime dKey in keys)
			{
				DateTime dtPlus = dKey.Date.AddDays(_interval);
				if (dt.CompareTo(dtPlus) >= 0)
					continue;
				return dKey;
			}
			return dtRet;
		}

		private void InsertIntoTable()
		{
			foreach (DictionaryEntry de in _odRooms)
			{
				Room rm = (Room)de.Value;
				for (int i = 0; i < rm.OdUsage.Count; i++)
				{
					RoomUsage ru = (RoomUsage)rm.OdUsage[i];
					DoInsert(rm.Name, ru);
				}
			}
		}

		private void DoInsert(string roomName, RoomUsage ru)
		{
			string sql = "INSERT INTO RoomUsage (VisitDate,RoomName,RoomUsage) VALUES(@VisitDate,@RoomName,@RoomUsage)";
			string connStr = ConfigurationManager.ConnectionStrings["CreamConnectString"].ToString();
			try
			{
				using (SqlConnection conn = new SqlConnection(connStr))
				{
					conn.Open();
					SqlCommand cmd = new SqlCommand(sql, conn);
					SqlParameter param = new SqlParameter("@VisitDate", ru.VisitDate);
					cmd.Parameters.Add(param);
					param = new SqlParameter("@RoomName", roomName);
					cmd.Parameters.Add(param);
					param = new SqlParameter("@RoomUsage", ru.Duration);
					cmd.Parameters.Add(param);

					cmd.ExecuteNonQuery();
				}
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
		}

		private bool IsVisitInHour(string tIn, string tOut, int hour)
		{
			//time in
			int hrsIn = 0;
			int minsIn = 0;

			//in hrs
			int pos = tIn.IndexOf(':');
			string sHrs = tIn.Substring(0, pos);
			hrsIn = int.Parse(sHrs);

			//in mins
			string sMins = tIn.Substring(pos + 1);
			minsIn = int.Parse(sMins);

			//time out
			int hrsOut = 0;
			int minsOut = 0;

			//out hrs
			pos = tOut.IndexOf(':');
			sHrs = tOut.Substring(0, pos);
			hrsOut = int.Parse(sHrs);

			//out mins
			sMins = tOut.Substring(pos + 1);
			minsOut = int.Parse(sMins);

			if (hrsIn == hour)
				return true;
			if (hrsIn > hour)
				return false;
			if (hrsOut >= hour)
				return true;
			return false;
		}

		private decimal GetHours(string tIn, string tOut)
		{
			//time in
			int hrsIn = 0;
			int minsIn = 0;

			//in hrs
			int pos = tIn.IndexOf(':');
			string sHrs = tIn.Substring(0, pos);
			hrsIn = int.Parse(sHrs);

			//in mins
			string sMins = tIn.Substring(pos + 1);
			minsIn = int.Parse(sMins);

			//time out
			int hrsOut = 0;
			int minsOut = 0;

			//out hrs
			pos = tOut.IndexOf(':');
			sHrs = tOut.Substring(0, pos);
			hrsOut = int.Parse(sHrs);

			//out mins
			sMins = tOut.Substring(pos + 1);
			minsOut = int.Parse(sMins);

			int totMins = 0;
			int hrs = hrsOut - hrsIn;

			totMins = hrs * 60 + (minsOut - minsIn);
			return (decimal)totMins / 60;
		}

		private void rdlAll_CheckedChanged(object sender, EventArgs e)
		{
			if (rdlAll.Checked)
			{
				chkC1.Checked = true;
				chkC2.Checked = true;
				chkE1.Checked = true;
				chkE2.Checked = true;
				chkE3.Checked = true;
				chkE4.Checked = true;
				chkC1.Enabled = false;
				chkC2.Enabled = false;
				chkE1.Enabled = false;
				chkE2.Enabled = false;
				chkE3.Enabled = false;
				chkE4.Enabled = false;
			}
			else
			{
				chkC1.Enabled = true;
				chkC2.Enabled = true;
				chkE1.Enabled = true;
				chkE2.Enabled = true;
				chkE3.Enabled = true;
				chkE4.Enabled = true;
			}
		}

		private void btnConcurrency_Click(object sender, EventArgs e)
		{
			if (!InitializeConcurrency())
				return;
			string url = Properties.Settings.Default.Crema2_ReportingServices_ReportingService.ToString().Trim();
			string server = GetServerFromUrl(url);
			StringBuilder sb = new StringBuilder("http://" + server + "/reportserver?");
			sb.Append("/GCRC/Room+Concurrency&rs:Command=Render");
			System.Diagnostics.Process.Start(sb.ToString());
		}

		private bool InitializeConcurrency()
		{
			if (StartDate.IsNullDate || EndDate.IsNullDate)
			{
				MessageBox.Show("Select start and end dates");
				return false;
			}

			_odConcurrent = new OrderedDictionary();
			_odSummaryHours = new OrderedDictionary();
			DateTime start = StartDate.Value.Date;
			DateTime end = EndDate.Value.Date;

			if (start.CompareTo(end) > 0)
			{
				MessageBox.Show("The start date must be equal to or great than the end date");
				return false;
			}

			while (start.CompareTo(end) < 1)
			{
				ProcessVistsForDate(start);
				start = start.AddDays(1);
			}
			if (_odConcurrent.Count > 0)
				InsertConcurrency();
			return true;
		}

		private void InsertConcurrency()
		{
			string sql = "TRUNCATE TABLE RoomConcurrency";
			string connStr = ConfigurationManager.ConnectionStrings["CreamConnectString"].ToString();
			try
			{
				using (SqlConnection conn = new SqlConnection(connStr))
				{
					conn.Open();
					SqlCommand cmd = new SqlCommand(sql, conn);
					cmd.ExecuteNonQuery();
				}

				IDictionaryEnumerator enumerator = _odConcurrent.GetEnumerator();

				while (enumerator.MoveNext())
				{
					DateTime date = (DateTime)enumerator.Key;
					ArrayList al = (ArrayList)enumerator.Value;

					foreach (Concurrency cn in al)
					{
						InsertIntoConcurTable(date, cn.Hour, cn.RoomsUsed, cn.Rooms);
					}
				}
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
		}

		private void InsertIntoConcurTable(DateTime date, int hour, int used, string rooms)
		{
			string connStr = ConfigurationManager.ConnectionStrings["CreamConnectString"].ToString();
			string sql = "INSERT INTO RoomConcurrency (VisitDate, Hour, RoomsUsed, Rooms) " +
				" VALUES (@VisitDate, @Hour, @RoomsUsed, @Rooms)";

			try
			{
				using (SqlConnection conn = new SqlConnection(connStr))
				{
					conn.Open();
					SqlCommand cmd = new SqlCommand(sql, conn);

					SqlParameter param = new SqlParameter("@VisitDate", date);
					cmd.Parameters.Add(param);
					param = new SqlParameter("@Hour", hour);
					cmd.Parameters.Add(param);
					param = new SqlParameter("@RoomsUsed", used);
					cmd.Parameters.Add(param);
					param = new SqlParameter("@Rooms", rooms);
					cmd.Parameters.Add(param);

					cmd.ExecuteNonQuery();
				}
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
		}

		private void ProcessVistsForDate(DateTime start)
		{
			string connStr = ConfigurationManager.ConnectionStrings["CreamConnectString"].ToString();
			string sql = "SELECT p.VisitDate, p.Room1 AS Room, p.Rm1TimeIn AS TimeIn, " +
				" p.Rm1TimeOut AS TimeOut, r.Display AS RoomName " +
				" FROM ProtocolVisitOutPatient AS p " +
				" INNER JOIN Rooms_L AS r ON r.ID = p.Room1 " +
				" WHERE (p.Room1 IS NOT NULL) AND (p.Room1 > 1) " +
				" AND (p.VisitDate = '" + start.ToShortDateString() + "')" +
				" UNION " +
				" SELECT p.VisitDate, p.Room2 AS Room, p.Rm2TimeIn AS TimeIn, " +
				" p.Rm2TimeOut AS TimeOut, r.Display AS RoomName " +
				" FROM ProtocolVisitOutPatient AS p " +
				" INNER JOIN Rooms_L AS r ON r.ID = p.Room2 " +
				" WHERE (p.Room2 IS NOT NULL) AND (p.Room2 > 1) " +
				" AND (p.VisitDate = '" + start.ToShortDateString() + "') " +
				" ORDER BY TimeIn";

			if (chkAdditional.Checked)
			{
				sql = "SELECT p.VisitDate, p.Room1 AS Room, p.Rm1TimeIn AS TimeIn, " +
				" p.Rm1TimeOut AS TimeOut, r.Display AS RoomName " +
				" FROM ProtocolVisitOutPatient AS p " +
				" INNER JOIN Rooms_L AS r ON r.ID = p.Room1 " +
				" WHERE (p.Room1 IS NOT NULL) AND (p.Room1 > 1) " +
				" AND (p.VisitDate = '" + start.ToShortDateString() + "')" +
				" UNION " +
				" SELECT p.VisitDate, p.Room2 AS Room, p.Rm2TimeIn AS TimeIn, " +
				" p.Rm2TimeOut AS TimeOut, r.Display AS RoomName " +
				" FROM ProtocolVisitOutPatient AS p " +
				" INNER JOIN Rooms_L AS r ON r.ID = p.Room2 " +
				" WHERE (p.Room2 IS NOT NULL) AND (p.Room2 > 1) " +
				" AND (p.VisitDate = '" + start.ToShortDateString() + "') " +
				" SELECT p.VisitDate, p.Room1 AS Room, p.Rm1TimeIn AS TimeIn, " +
				" p.Rm1TimeOut AS TimeOut, r.Display AS RoomName " +
				" FROM AdditionalRoomUsage AS p " +
				" INNER JOIN Rooms_L AS r ON r.ID = p.Room1 " +
				" WHERE (p.Room1 IS NOT NULL) AND (p.Room1 > 1) " +
				" AND (p.VisitDate = '" + start.ToShortDateString() + "')" +
				" UNION " +
				" SELECT p.VisitDate, p.Room2 AS Room, p.Rm2TimeIn AS TimeIn, " +
				" p.Rm2TimeOut AS TimeOut, r.Display AS RoomName " +
				" FROM AdditionalRoomUsage AS p " +
				" INNER JOIN Rooms_L AS r ON r.ID = p.Room2 " +
				" WHERE (p.Room2 IS NOT NULL) AND (p.Room2 > 1) " +
				" AND (p.VisitDate = '" + start.ToShortDateString() + "') " +
				" ORDER BY TimeIn";
			}

			if (start.DayOfWeek == DayOfWeek.Sunday)
				return;
			if (IsHoliday(start))
				return;
			try
			{
				SqlConnection conn = new SqlConnection(connStr);
				SqlDataAdapter da = new SqlDataAdapter(sql, connStr);
				DataTable dt = new DataTable();
				da.Fill(dt);

				//if there are rows means that there are visits for this day.
				//TODO - how can you tell if there were no visits but was an operational day?                
				if (dt.Rows.Count > 0)
				{
					//create a dictionary entry
					ArrayList al = new ArrayList();
					_odConcurrent.Add(start, al);


					//look at gcrc open hours 7 to 7
					for (int hour = 7; hour < 20; hour++)
					{
						bool b = true;
						if (start.DayOfWeek == DayOfWeek.Thursday && hour == 18)
							b = false;

						SummaryHourRoomUsage sru = null;
						//create or get summary entry
						if (!_odSummaryHours.Contains(hour.ToString()))
						{
							sru = new SummaryHourRoomUsage();
							sru.Hour = hour;
							_odSummaryHours.Add(hour.ToString(), sru);
						}
						else
							sru = (SummaryHourRoomUsage)_odSummaryHours[hour.ToString()];

						SummaryDayRoomUsage dru = sru.DaySummaryList[start.DayOfWeek];

						Concurrency cn = new Concurrency();
						cn.Hour = hour;
						al.Add(cn);

						if (IsOperationalHour(start.DayOfWeek, hour))
						{
							sru.OperationalDays++;
							if (!dru.OperationalDays.ContainsKey(start))
								dru.OperationalDays.Add(start, start);
						}
						else
						{
							cn.IsOperational = false;
						}

						foreach (DataRow dr in dt.Rows)
						{
							string timeIn = dr["TimeIn"].ToString();
							string timeOut = dr["TimeOut"].ToString();

							if (IsVisitInHour(timeIn, timeOut, hour))
							{
								//if this wasn't an operational but there was activitiy then make it an opereational day
								if (!cn.IsOperational)
								{
									cn.IsOperational = true;
									sru.OperationalDays++;
									if (!dru.OperationalDays.ContainsKey(start))
										dru.OperationalDays.Add(start, start);
								}
								RoomType rt = GetRoomType(dr["RoomName"].ToString());
								//UpdateSummary

								if (rt == RoomType.Exam)
								{
									dru.Exams++;
									sru.Exams++;
									cn.Exams++;
								}
								else
								{
									dru.Consults++;
									sru.Consults++;
									cn.Consults++;
								}
								sru.Census++;
								dru.Census++;

								//concurrency 
								cn.RoomsUsed++;
								if (cn.Rooms.Length == 0)
									cn.Rooms = dr["RoomName"].ToString();
								else
									cn.Rooms += "," + dr["RoomName"].ToString();
							}
						}//foreach (DataRow dr in dt.Rows)
					}//for (int hour = 7; hour < 19; hour++)
				}//if (dt.Rows.Count > 0)
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
		}

		private RoomType GetRoomType(string roomName)
		{
			if (roomName.StartsWith("E"))
				return RoomType.Exam;
			return RoomType.Consult;
		}

		private void btnVisitDetail_Click(object sender, EventArgs e)
		{
			if (StartDate.IsNullDate || EndDate.IsNullDate)
			{
				MessageBox.Show("Select start and end dates");
				return;
			}

			string sql = "TRUNCATE TABLE RoomVisitDetail";
			string connStr = ConfigurationManager.ConnectionStrings["CreamConnectString"].ToString();
			try
			{
				using (SqlConnection conn = new SqlConnection(connStr))
				{
					conn.Open();
					SqlCommand cmd = new SqlCommand(sql, conn);
					cmd.ExecuteNonQuery();


					sql = "INSERT INTO RoomVisitDetail " +
						"SELECT p.VisitDate, p.ID, p.Patient, pr.ProtocolNumber, " +
						"r.Display AS Room, p.Rm1TimeIn AS TimeIn, p.Rm1TimeOut AS TimeOut " +
						"FROM ProtocolVisitOutPatient AS p INNER JOIN " +
						"Rooms_L AS r ON r.ID = p.Room1 INNER JOIN " +
						"Protocol pr ON p.Protocol = pr.ID " +
						"WHERE (p.Room1 IS NOT NULL) AND (p.Room1 > 1) AND " +
						"(p.VisitDate BETWEEN '" + StartDate.Value.ToShortDateString() +
						"' AND '" + EndDate.Value.ToShortDateString() + "') " +
						"UNION " +
						"SELECT p.VisitDate, p.ID, p.Patient, pr.ProtocolNumber, " +
						"r.Display AS Room, p.Rm2TimeIn AS TimeIn, p.Rm2TimeOut AS TimeOut " +
						"FROM ProtocolVisitOutPatient AS p INNER JOIN " +
						"Rooms_L AS r ON r.ID = p.Room2 INNER JOIN " +
						"Protocol pr ON p.Protocol = pr.ID " +
						"WHERE (p.Room2 IS NOT NULL) AND (p.Room2 > 1) AND " +
						"(p.VisitDate BETWEEN '" + StartDate.Value.ToShortDateString() +
						"' AND '" + EndDate.Value.ToShortDateString() + "') " +
						"ORDER BY VisitDate, TimeIn";

					if (chkAdditional.Checked)
					{
						sql = "INSERT INTO RoomVisitDetail " +
						"SELECT p.VisitDate, p.ID, p.Patient, pr.ProtocolNumber, " +
						"r.Display AS Room, p.Rm1TimeIn AS TimeIn, p.Rm1TimeOut AS TimeOut " +
						"FROM ProtocolVisitOutPatient AS p INNER JOIN " +
						"Rooms_L AS r ON r.ID = p.Room1 INNER JOIN " +
						"Protocol pr ON p.Protocol = pr.ID " +
						"WHERE (p.Room1 IS NOT NULL) AND (p.Room1 > 1) AND " +
						"(p.VisitDate BETWEEN '" + StartDate.Value.ToShortDateString() +
						"' AND '" + EndDate.Value.ToShortDateString() + "') " +
						"UNION " +
						"SELECT p.VisitDate, p.ID, p.Patient, pr.ProtocolNumber, " +
						"r.Display AS Room, p.Rm2TimeIn AS TimeIn, p.Rm2TimeOut AS TimeOut " +
						"FROM ProtocolVisitOutPatient AS p INNER JOIN " +
						"Rooms_L AS r ON r.ID = p.Room2 INNER JOIN " +
						"Protocol pr ON p.Protocol = pr.ID " +
						"WHERE (p.Room2 IS NOT NULL) AND (p.Room2 > 1) AND " +
						"(p.VisitDate BETWEEN '" + StartDate.Value.ToShortDateString() +
						"' AND '" + EndDate.Value.ToShortDateString() + "') " +
						"UNION " +
						"SELECT a.VisitDate, a.ID, 0 AS Patient, ISNULL(pr.ProtocolNumber, '') AS ProtocolNumber, " +
						"r.Display AS Room, a.Rm1TimeIn AS TimeIn, a.Rm1TimeOut AS TimeOut " +
						"FROM AdditionalRoomUsage AS a INNER JOIN " +
						"Rooms_L AS r ON r.ID = a.Room1 LEFT JOIN " +
						"Protocol pr ON a.Protocol = pr.ID " +
						"WHERE (a.Room1 IS NOT NULL) AND (a.Room1 > 1) AND " +
						"(a.VisitDate BETWEEN '" + StartDate.Value.ToShortDateString() +
						"' AND '" + EndDate.Value.ToShortDateString() + "') " +
						"UNION " +
						"SELECT a.VisitDate, a.ID, 0 AS Patient, ISNULL(pr.ProtocolNumber, '') AS ProtocolNumber, " +
						"r.Display AS Room, a.Rm2TimeIn AS TimeIn, a.Rm2TimeOut AS TimeOut " +
						"FROM AdditionalRoomUsage AS a INNER JOIN " +
						"Rooms_L AS r ON r.ID = a.Room2 LEFT JOIN " +
						"Protocol pr ON a.Protocol = pr.ID " +
						"WHERE (a.Room2 IS NOT NULL) AND (a.Room2 > 1) AND " +
						"(a.VisitDate BETWEEN '" + StartDate.Value.ToShortDateString() +
						"' AND '" + EndDate.Value.ToShortDateString() + "') " +
						"ORDER BY VisitDate, TimeIn";
					}

					cmd = new SqlCommand(sql, conn);
					cmd.ExecuteNonQuery();
					string url = Properties.Settings.Default.Crema2_ReportingServices_ReportingService.ToString().Trim();
					string server = GetServerFromUrl(url);
					StringBuilder sb = new StringBuilder("http://" + server + "/reportserver?");
					sb.Append("/GCRC/Room+Visit+Detail&rs:Command=Render");
					System.Diagnostics.Process.Start(sb.ToString());
				}
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
		}

		private void button2_Click(object sender, EventArgs e)
		{
			this.Close();
		}

		private void frmRoomReports_Load(object sender, EventArgs e)
		{
			//StartDate.Value = DateTime.Parse("06/01/2008");
			//EndDate.Value = DateTime.Parse("06/30/2008");
			StartDate.Value = DateTime.Today;
			EndDate.Value = DateTime.Today;
			StartDate.IsNullDate = true;
			EndDate.IsNullDate = true;
		}

		private string GetServerFromUrl(string url)
		{
			int pos1 = url.IndexOf("//");
			int pos2 = url.IndexOf("/", pos1 + 2);

			string retVal = url.Substring(pos1 + 2, (pos2 - pos1) - 2);
			return retVal;
		}

		private void btnCreateSS_Click(object sender, EventArgs e)
		{
			try
			{

				SaveFileDialog dlg = new SaveFileDialog();
				dlg.DefaultExt = "xls";
				dlg.Filter = "Excel|*.xls";
				dlg.ShowDialog();
				if (dlg.FileName.Length == 0)
					return;

				if (!InitializeConcurrency())
					return;

				ExcelEngine eeng = new ExcelEngine();
				IApplication eapp = eeng.Excel;
				IWorkbook wb = eapp.Workbooks.Create();
				IWorksheet ws = wb.Worksheets[0];
				CreateHeading(ws);

				int row = 5;
				CreateMainBody(ws, ref row);

				row += 2;
				CreateHourSummaryHeading(ws, row);
				row++;
				CreateHourSummary(ws, row);

				row += 2;
				CreateDayHourSummaryHeading(ws, row);

				row += 2;
				CreateDayHourSummary(ws, row);

				wb.SaveAs(dlg.FileName, ExcelSaveType.SaveAsXLS);
				wb.Close();
				eeng.Dispose();
				MessageBox.Show(dlg.FileName + " was created");
			}
			catch (Exception ex)
			{
				string s = ex.Message + Environment.NewLine + ex.StackTrace;
				MessageBox.Show(s);
			}
		}

		private void CreateDayHourSummary(IWorksheet ws, int row)
		{
			IDictionaryEnumerator enumerator = _odSummaryHours.GetEnumerator();
			int col = 3;
			string numFormat = "#0%";
			SummaryDayRoomUsage dru = null;
			int opDays = 0;
			double totRooms = 0;
			double totExamRooms = 0;
			double totConsultRooms = 0;
			double patientPer = 0;
			double percent = 0;

			while (enumerator.MoveNext())
			{
				string hour = enumerator.Key.ToString();
				SummaryHourRoomUsage sru = (SummaryHourRoomUsage)enumerator.Value;

				//monday
				dru = sru.DaySummaryList[DayOfWeek.Monday];
				opDays = dru.OperationalDays.Count;

				totRooms = opDays * _totRooms;
				totExamRooms = opDays * _totExamRooms;
				totConsultRooms = opDays * _totConsultRooms;

				if (opDays == 0)
				{
					patientPer = 0;
					ws[row, col].CellStyle.ColorIndex = ExcelKnownColors.Aqua;
				}
				else
					patientPer = dru.Census / (double)opDays;
				ws[row, col].Number = patientPer;
				ws[row, col].NumberFormat = "0.0";
				ws[row, col].CellStyle.Font.Size = 8;

				if (opDays == 0)
				{
					percent = 0;
					ws[row, col + 1].CellStyle.ColorIndex = ExcelKnownColors.Aqua;
				}
				else
					percent = dru.Census / totRooms;
				ws[row, col + 1].Number = percent;
				ws[row, col + 1].NumberFormat = numFormat;
				ws[row, col + 1].CellStyle.Font.Size = 8;

				if (opDays == 0)
				{
					percent = 0;
					ws[row, col + 2].CellStyle.ColorIndex = ExcelKnownColors.Aqua;
				}
				else
					percent = dru.Exams / totExamRooms;
				ws[row, col + 2].Number = percent;
				ws[row, col + 2].NumberFormat = numFormat;
				ws[row, col + 2].CellStyle.Font.Size = 8;

				if (opDays == 0)
				{
					percent = 0;
					ws[row, col + 3].CellStyle.ColorIndex = ExcelKnownColors.Aqua;
				}
				else
					percent = dru.Consults / totConsultRooms;
				ws[row, col + 3].Number = percent;
				ws[row, col + 3].NumberFormat = numFormat;
				ws[row, col + 3].CellStyle.Font.Size = 8;

				//tuesday
				dru = sru.DaySummaryList[DayOfWeek.Tuesday];
				opDays = dru.OperationalDays.Count;

				totRooms = opDays * _totRooms;
				totExamRooms = opDays * _totExamRooms;
				totConsultRooms = opDays * _totConsultRooms;

				if (opDays == 0)
				{
					patientPer = 0;
					ws[row + 1, col].CellStyle.ColorIndex = ExcelKnownColors.Aqua;
				}
				else
					patientPer = dru.Census / (double)opDays;
				ws[row + 1, col].Number = patientPer;
				ws[row + 1, col].NumberFormat = "0.0";
				ws[row + 1, col].CellStyle.Font.Size = 8;

				if (opDays == 0)
				{
					percent = 0;
					ws[row + 1, col + 1].CellStyle.ColorIndex = ExcelKnownColors.Aqua;
				}
				else
					percent = dru.Census / totRooms;
				ws[row + 1, col + 1].Number = percent;
				ws[row + 1, col + 1].NumberFormat = numFormat;
				ws[row + 1, col + 1].CellStyle.Font.Size = 8;

				if (opDays == 0)
				{
					percent = 0;
					ws[row + 1, col + 2].CellStyle.ColorIndex = ExcelKnownColors.Aqua;
				}
				else
					percent = dru.Exams / totExamRooms;
				ws[row + 1, col + 2].Number = percent;
				ws[row + 1, col + 2].NumberFormat = numFormat;
				ws[row + 1, col + 2].CellStyle.Font.Size = 8;

				if (opDays == 0)
				{
					percent = 0;
					ws[row + 1, col + 3].CellStyle.ColorIndex = ExcelKnownColors.Aqua;
				}
				else
					percent = dru.Consults / totConsultRooms;
				ws[row + 1, col + 3].Number = percent;
				ws[row + 1, col + 3].NumberFormat = numFormat;
				ws[row + 1, col + 3].CellStyle.Font.Size = 8;

				//wednesday
				dru = sru.DaySummaryList[DayOfWeek.Wednesday];
				opDays = dru.OperationalDays.Count;

				totRooms = opDays * _totRooms;
				totExamRooms = opDays * _totExamRooms;
				totConsultRooms = opDays * _totConsultRooms;

				if (opDays == 0)
				{
					patientPer = 0;
					ws[row + 2, col].CellStyle.ColorIndex = ExcelKnownColors.Aqua;
				}
				else
					patientPer = dru.Census / (double)opDays;
				ws[row + 2, col].Number = patientPer;
				ws[row + 2, col].NumberFormat = "0.0";
				ws[row + 2, col].CellStyle.Font.Size = 8;

				if (opDays == 0)
				{
					percent = 0;
					ws[row + 2, col + 1].CellStyle.ColorIndex = ExcelKnownColors.Aqua;
				}
				else
					percent = dru.Census / totRooms;
				ws[row + 2, col + 1].Number = percent;
				ws[row + 2, col + 1].NumberFormat = numFormat;
				ws[row + 2, col + 1].CellStyle.Font.Size = 8;

				if (opDays == 0)
				{
					percent = 0;
					ws[row + 2, col + 2].CellStyle.ColorIndex = ExcelKnownColors.Aqua;
				}
				else
					percent = dru.Exams / totExamRooms;
				ws[row + 2, col + 2].Number = percent;
				ws[row + 2, col + 2].NumberFormat = numFormat;
				ws[row + 2, col + 2].CellStyle.Font.Size = 8;

				if (opDays == 0)
				{
					percent = 0;
					ws[row + 2, col + 3].CellStyle.ColorIndex = ExcelKnownColors.Aqua;
				}
				else
					percent = dru.Consults / totConsultRooms;
				ws[row + 2, col + 3].Number = percent;
				ws[row + 2, col + 3].NumberFormat = numFormat;
				ws[row + 2, col + 3].CellStyle.Font.Size = 8;

				//thursday
				dru = sru.DaySummaryList[DayOfWeek.Thursday];
				opDays = dru.OperationalDays.Count;

				totRooms = opDays * _totRooms;
				totExamRooms = opDays * _totExamRooms;
				totConsultRooms = opDays * _totConsultRooms;

				if (opDays == 0)
				{
					patientPer = 0;
					ws[row + 3, col].CellStyle.ColorIndex = ExcelKnownColors.Aqua;
				}
				else
					patientPer = dru.Census / (double)opDays;
				ws[row + 3, col].Number = patientPer;
				ws[row + 3, col].NumberFormat = "0.0";
				ws[row + 3, col].CellStyle.Font.Size = 8;

				if (opDays == 0)
				{
					percent = 0;
					ws[row + 3, col + 1].CellStyle.ColorIndex = ExcelKnownColors.Aqua;
				}
				else
					percent = dru.Census / totRooms;
				ws[row + 3, col + 1].Number = percent;
				ws[row + 3, col + 1].NumberFormat = numFormat;
				ws[row + 3, col + 1].CellStyle.Font.Size = 8;

				if (opDays == 0)
				{
					percent = 0;
					ws[row + 3, col + 2].CellStyle.ColorIndex = ExcelKnownColors.Aqua;
				}
				else
					percent = dru.Exams / totExamRooms;
				ws[row + 3, col + 2].Number = percent;
				ws[row + 3, col + 2].NumberFormat = numFormat;
				ws[row + 3, col + 2].CellStyle.Font.Size = 8;

				if (opDays == 0)
				{
					percent = 0;
					ws[row + 3, col + 3].CellStyle.ColorIndex = ExcelKnownColors.Aqua;
				}
				else
					percent = dru.Consults / totConsultRooms;
				ws[row + 3, col + 3].Number = percent;
				ws[row + 3, col + 3].NumberFormat = numFormat;
				ws[row + 3, col + 3].CellStyle.Font.Size = 8;

				//friday
				dru = sru.DaySummaryList[DayOfWeek.Friday];
				opDays = dru.OperationalDays.Count;

				totRooms = opDays * _totRooms;
				totExamRooms = opDays * _totExamRooms;
				totConsultRooms = opDays * _totConsultRooms;

				if (opDays == 0)
				{
					patientPer = 0;
					ws[row + 4, col].CellStyle.ColorIndex = ExcelKnownColors.Aqua;
				}
				else
					patientPer = dru.Census / (double)opDays;
				ws[row + 4, col].Number = patientPer;
				ws[row + 4, col].NumberFormat = "0.0";
				ws[row + 4, col].CellStyle.Font.Size = 8;

				if (opDays == 0)
				{
					percent = 0;
					ws[row + 4, col + 1].CellStyle.ColorIndex = ExcelKnownColors.Aqua;
				}
				else
					percent = dru.Census / totRooms;
				ws[row + 4, col + 1].Number = percent;
				ws[row + 4, col + 1].NumberFormat = numFormat;
				ws[row + 4, col + 1].CellStyle.Font.Size = 8;

				if (opDays == 0)
				{
					percent = 0;
					ws[row + 4, col + 2].CellStyle.ColorIndex = ExcelKnownColors.Aqua;
				}
				else
					percent = dru.Exams / totExamRooms;
				ws[row + 4, col + 2].Number = percent;
				ws[row + 4, col + 2].NumberFormat = numFormat;
				ws[row + 4, col + 2].CellStyle.Font.Size = 8;

				if (opDays == 0)
				{
					percent = 0;
					ws[row + 4, col + 3].CellStyle.ColorIndex = ExcelKnownColors.Aqua;
				}
				else
					percent = dru.Consults / totConsultRooms;
				ws[row + 4, col + 3].Number = percent;
				ws[row + 4, col + 3].NumberFormat = numFormat;
				ws[row + 4, col + 3].CellStyle.Font.Size = 8;

				//saturday
				dru = sru.DaySummaryList[DayOfWeek.Saturday];
				opDays = dru.OperationalDays.Count;

				totRooms = opDays * _totRooms;
				totExamRooms = opDays * _totExamRooms;
				totConsultRooms = opDays * _totConsultRooms;

				if (opDays == 0)
				{
					patientPer = 0;
					ws[row + 5, col].CellStyle.ColorIndex = ExcelKnownColors.Aqua;
				}
				else
					patientPer = dru.Census / (double)opDays;
				ws[row + 5, col].Number = patientPer;
				ws[row + 5, col].NumberFormat = "0.0";
				ws[row + 5, col].CellStyle.Font.Size = 8;

				if (opDays == 0)
				{
					percent = 0;
					ws[row + 5, col + 1].CellStyle.ColorIndex = ExcelKnownColors.Aqua;
				}
				else
					percent = dru.Census / totRooms;
				ws[row + 5, col + 1].Number = percent;
				ws[row + 5, col + 1].NumberFormat = numFormat;
				ws[row + 5, col + 1].CellStyle.Font.Size = 8;

				if (opDays == 0)
				{
					percent = 0;
					ws[row + 5, col + 2].CellStyle.ColorIndex = ExcelKnownColors.Aqua;
				}
				else
					percent = dru.Exams / totExamRooms;
				ws[row + 5, col + 2].Number = percent;
				ws[row + 5, col + 2].NumberFormat = numFormat;
				ws[row + 5, col + 2].CellStyle.Font.Size = 8;

				if (opDays == 0)
				{
					percent = 0;
					ws[row + 5, col + 3].CellStyle.ColorIndex = ExcelKnownColors.Aqua;
				}
				else
					percent = dru.Consults / totConsultRooms;
				ws[row + 5, col + 3].Number = percent;
				ws[row + 5, col + 3].NumberFormat = numFormat;
				ws[row + 5, col + 3].CellStyle.Font.Size = 8;
				col += 4;
			}
		}

		private void CreateHourSummary(IWorksheet ws, int row)
		{
			IDictionaryEnumerator enumerator = _odSummaryHours.GetEnumerator();
			int col = 3;
			string numFormat = "#0%";
			double patientPer = 0;
			double percent = 0;
			while (enumerator.MoveNext())
			{
				string hour = enumerator.Key.ToString();

				SummaryHourRoomUsage sru = (SummaryHourRoomUsage)enumerator.Value;

				double totRooms = sru.OperationalDays * _totRooms;
				double totExamRooms = sru.OperationalDays * _totExamRooms;
				double totConsultRooms = sru.OperationalDays * _totConsultRooms;

				if (sru.OperationalDays == 0)
				{
					ws[row, col].CellStyle.ColorIndex = ExcelKnownColors.Aqua;
					patientPer = 0;
				}
				else
					patientPer = sru.Census / (double)sru.OperationalDays;
				ws[row, col].Number = patientPer;
				ws[row, col].NumberFormat = "0.0";
				ws[row, col].CellStyle.Font.Size = 8;

				if (sru.OperationalDays == 0)
				{
					ws[row, col + 1].CellStyle.ColorIndex = ExcelKnownColors.Aqua;
					percent = 0;
				}
				else
					percent = sru.Census / totRooms;
				ws[row, col + 1].Number = percent;
				ws[row, col + 1].NumberFormat = numFormat;
				ws[row, col + 1].CellStyle.Font.Size = 8;

				if (sru.OperationalDays == 0)
				{
					ws[row, col + 2].CellStyle.ColorIndex = ExcelKnownColors.Aqua;
					percent = 0;
				}
				else
					percent = sru.Exams / totExamRooms;
				ws[row, col + 2].Number = percent;
				ws[row, col + 2].NumberFormat = numFormat;
				ws[row, col + 2].CellStyle.Font.Size = 8;

				if (sru.OperationalDays == 0)
				{
					ws[row, col + 3].CellStyle.ColorIndex = ExcelKnownColors.Aqua;
					percent = 0;
				}
				else
					percent = sru.Consults / totConsultRooms;
				ws[row, col + 3].Number = percent;
				ws[row, col + 3].NumberFormat = numFormat;
				ws[row, col + 3].CellStyle.Font.Size = 8;
				col += 4;
			}
		}

		private void CreateMainBody(IWorksheet ws, ref int row)
		{
			IDictionaryEnumerator enumerator = _odConcurrent.GetEnumerator();
			while (enumerator.MoveNext())
			{
				DateTime date = (DateTime)enumerator.Key;
				ArrayList al = (ArrayList)enumerator.Value;
				ws[row, 1].Text = date.ToShortDateString();
				ws[row, 2].Text = date.DayOfWeek.ToString();

				int col = 3;
				string numFormat = "#0%";
				for (int i = 0; i < al.Count; i++)
				{
					Concurrency cn = al[i] as Concurrency;
					if (!cn.IsOperational)
					{
						//ws[row, col + 1].CellStyle.ColorIndex = ExcelKnownColors.Aqua;
						//ws[row, col + 2].CellStyle.ColorIndex = ExcelKnownColors.Aqua;
						//ws[row, col + 3].CellStyle.ColorIndex = ExcelKnownColors.Aqua;
					}

					ws[row, col].Number = cn.RoomsUsed;
					double percent = cn.RoomsUsed / _totRooms;
					string sPercent = percent.ToString() + "%";
					//ws[row, col + 1].Text = sPercent;
					ws[row, col + 1].Number = percent;
					ws[row, col + 1].NumberFormat = numFormat;
					ws[row, col + 1].CellStyle.Font.Size = 8;

					percent = cn.Exams / _totExamRooms;
					sPercent = percent.ToString() + "%";
					//ws[row, col + 2].Text = sPercent;
					ws[row, col + 2].Number = percent;
					ws[row, col + 2].NumberFormat = numFormat;
					ws[row, col + 2].CellStyle.Font.Size = 8;

					percent = cn.Consults / _totConsultRooms;
					sPercent = percent.ToString() + "%";
					//ws[row, col + 3].Text = sPercent;
					ws[row, col + 3].Number = percent;
					ws[row, col + 3].NumberFormat = numFormat;
					ws[row, col + 3].CellStyle.Font.Size = 8;


					col += 4;
				}
				row++;
			}
		}

		private void CreateDayHourSummaryHeading(IWorksheet ws, int row)
		{

			ws[row, 2].Text = "Summary Day Averages By Hour";

			int col = 3;
			row++;
			for (int h = 7; h < 20; h++)
			{
				ws.Range[row, col].Text = h + ":00";
				ws.Range[row, col + 1].Text = "T";
				ws.Range[row, col + 2].Text = "E";
				ws.Range[row, col + 3].Text = "C";

				col += 4;
			}

			ws.Range[row + 1, 2].Text = "Mondays";
			ws.Range[row + 2, 2].Text = "Tuesdays";
			ws.Range[row + 3, 2].Text = "Wednesdays";
			ws.Range[row + 4, 2].Text = "Thursdays";
			ws.Range[row + 5, 2].Text = "Fridays";
			ws.Range[row + 6, 2].Text = "Saturdays";

		}

		private void CreateHourSummaryHeading(IWorksheet ws, int row)
		{

			ws[row - 1, 2].Text = "Summary Averages By Hour";
			ws[row + 1, 2].Text = "Ave PPHr";

			int col = 3;
			for (int h = 7; h < 20; h++)
			{
				ws.Range[row, col].Text = h + ":00";
				ws.Range[row, col + 1].Text = "T";
				ws.Range[row, col + 2].Text = "E";
				ws.Range[row, col + 3].Text = "C";

				col += 4;
			}
		}

		private void CreateHeading(IWorksheet ws)
		{
			try
			{
				ws.Range[1, 1].Text = "Date";
				ws.Range[1, 2].Text = "Day";
				ws.Range[3, 1].Text = "Cap";
				int col = 3;
				for (int h = 7; h < 20; h++)
				{
					ws.Range[1, col].Text = "Census";
					ws.Range[1, col + 1, 1, col + 3].Merge();
					ws.Range[1, col + 1].Text = "% Room Cap";
					ws.Range[2, col].Text = h + ":00";
					ws.Range[2, col + 1].Text = "T";
					ws.Range[2, col + 2].Text = "E";
					ws.Range[2, col + 3].Text = "C";
					ws.Range[3, col + 1].Number = 6;
					ws.Range[3, col + 2].Number = 4;
					ws.Range[3, col + 3].Number = 2;

					ws.Range[2, col].CellStyle.HorizontalAlignment = ExcelHAlign.HAlignCenter;
					ws.Range[2, col + 1].CellStyle.HorizontalAlignment = ExcelHAlign.HAlignCenter;
					ws.Range[2, col + 2].CellStyle.HorizontalAlignment = ExcelHAlign.HAlignCenter;
					ws.Range[2, col + 3].CellStyle.HorizontalAlignment = ExcelHAlign.HAlignCenter;

					ws.Range[3, col].CellStyle.HorizontalAlignment = ExcelHAlign.HAlignCenter;
					ws.Range[3, col + 1].CellStyle.HorizontalAlignment = ExcelHAlign.HAlignCenter;
					ws.Range[3, col + 2].CellStyle.HorizontalAlignment = ExcelHAlign.HAlignCenter;
					ws.Range[3, col + 3].CellStyle.HorizontalAlignment = ExcelHAlign.HAlignCenter;

					col += 4;
				}

				col = 2;
				ws.Columns[0].ColumnWidth = 9;
				ws.Columns[1].ColumnWidth = 12;

				for (int h = 7; h < 20; h++)
				{
					ws.Columns[col].ColumnWidth = 6.5;
					for (int i = 1; i < 4; i++)
						ws.Columns[col + i].ColumnWidth = 4.5;

					col += 4;
				}
			}
			catch
			{
			}
		}

		private bool IsOperationalHour(DayOfWeek day, int hour)
		{
			switch (day)
			{
				case DayOfWeek.Monday:
					if (hour >= 8 && hour <= 17)
						return true;
					break;
				case DayOfWeek.Tuesday:
					if (hour >= 7 && hour <= 19)
						return true;
					break;
				case DayOfWeek.Wednesday:
					if (hour >= 8 && hour <= 17)
						return true;
					break;
				case DayOfWeek.Thursday:
					if (hour >= 7 && hour <= 19)
						return true;
					break;
				case DayOfWeek.Friday:
					if (hour >= 8 && hour <= 16)
						return true;
					break;
				case DayOfWeek.Saturday:
					if (hour >= 8 && hour <= 16)
						return true;
					break;
			}
			return false;
		}

		private bool IsHoliday(DateTime date)
		{
			if (date.Date.CompareTo(DateTime.Parse("01/01/2010")) == 0)
				return true;
			if (date.Date.CompareTo(DateTime.Parse("01/18/2010")) == 0)
				return true;
			if (date.Date.CompareTo(DateTime.Parse("02/15/2010")) == 0)
				return true;
			if (date.Date.CompareTo(DateTime.Parse("04/19/2010")) == 0)
				return true;
			if (date.Date.CompareTo(DateTime.Parse("05/31/2010")) == 0)
				return true;
			if (date.Date.CompareTo(DateTime.Parse("07/05/2010")) == 0)
				return true;
			if (date.Date.CompareTo(DateTime.Parse("11/11/2010")) == 0)
				return true;
			if (date.Date.CompareTo(DateTime.Parse("11/25/2010")) == 0)
				return true;
			if (date.Date.CompareTo(DateTime.Parse("12/24/2010")) == 0)
				return true;
			if (date.Date.CompareTo(DateTime.Parse("01/01/2009")) == 0)
				return true;
			if (date.Date.CompareTo(DateTime.Parse("01/19/2009")) == 0)
				return true;
			if (date.Date.CompareTo(DateTime.Parse("02/16/2009")) == 0)
				return true;
			if (date.Date.CompareTo(DateTime.Parse("04/20/2009")) == 0)
				return true;
			if (date.Date.CompareTo(DateTime.Parse("05/25/2009")) == 0)
				return true;
			if (date.Date.CompareTo(DateTime.Parse("07/03/2009")) == 0)
				return true;
			if (date.Date.CompareTo(DateTime.Parse("11/11/2009")) == 0)
				return true;
			if (date.Date.CompareTo(DateTime.Parse("11/26/2009")) == 0)
				return true;
			if (date.Date.CompareTo(DateTime.Parse("12/25/2009")) == 0)
				return true;
			if (date.Date.CompareTo(DateTime.Parse("01/01/2008")) == 0)
				return true;
			if (date.Date.CompareTo(DateTime.Parse("01/21/2008")) == 0)
				return true;
			if (date.Date.CompareTo(DateTime.Parse("02/18/2008")) == 0)
				return true;
			if (date.Date.CompareTo(DateTime.Parse("04/21/2008")) == 0)
				return true;
			if (date.Date.CompareTo(DateTime.Parse("05/26/2008")) == 0)
				return true;
			if (date.Date.CompareTo(DateTime.Parse("07/04/2008")) == 0)
				return true;
			if (date.Date.CompareTo(DateTime.Parse("11/11/2008")) == 0)
				return true;
			if (date.Date.CompareTo(DateTime.Parse("11/27/2008")) == 0)
				return true;
			if (date.Date.CompareTo(DateTime.Parse("12/25/2008")) == 0)
				return true;


			return false;
		}

		private void btnPercentCancels_Click(object sender, EventArgs e)
		{

		}
	}
}